//index.js
//获取应用实例
const app = getApp()
const host = require('../../config').host
const fraction1 = []
// let type1 = 0;
// let type2 = 0;
// let type3 = 0;
// let type4 = 0;
let value1 = "";
let value2 = "";
let value3 = "";
let value4 = "";

for (let i = 0; i <= 25; i++) {
  fraction1.push(i)
}

Page({
  data: {
    motto: 'Hello World',
    userInfo: {},
    hasUserInfo: false,
    fraction1:fraction1,
    number:"",
    value1:value1,
    value2:value2,
    value3:value3,
    value4:value4,
    lists:"display",
    session:1,
    currentReviewId: 0,
    currentTabId: 0,
    canIUse: wx.canIUse('button.open-type.getUserInfo')
  },
  bindChange: function (e) {
    var val = e.detail.value
    var that = this
    console.log(val)
    // console.log(e)
    var type = e.currentTarget.dataset.type;
    if(val > 100){
      wx.showModal({
          title: '提示',
          content: '最多可以100分',
          showCancel: false,
          success (res) {
            if (res.confirm) {
              // value1 = that.data.value1
            }
          }
        })
    }
     // var number = this.data.number
    if(val > 100){
      that.setData({
        number: "100"
      })
      }else{
        that.setData({
        number: val
      })
      }
    // number = this.data.number
    
    // console.log(value1)
    // console.log(type2)
    // console.log(type3)
    // console.log(type4)
    // var num = value1*1 + value2*1 + value3*1 + value4*1
    // var num = number*1
    // if(num){
    //   this.setData({
    //     number: num
    //   })
    // }
    
  },
  bindChange1: function (e) {
    var val = e.detail.value
    var that = this
    console.log(val)
    // console.log(e)
    var type = e.currentTarget.dataset.type;
    if(type == 1){
       this.setData({
        value1: val
      })
    }else if(type == 2){
    	this.setData({
        value2: val
      })
    }else if(type == 3){
    	this.setData({
        value3: val
      })
    }else if(type == 4){
    	this.setData({
        value4: val
      })
    }
    var value1 = this.data.value1
    if(value1 > 25){
      that.setData({
        value1: "25"
      })
      }
    value1 = this.data.value1
    var value2 = this.data.value2
    if(value2 > 25){
      that.setData({
        value2: "25"
      })
      }
    value2 = this.data.value2
    var value3 = this.data.value3
    if(value3 > 25){
      that.setData({
        value3: "25"
      })
      }
    value3 = this.data.value3
    if(val > 100){
      wx.showModal({
          title: '提示',
          content: '最多可以100分',
          showCancel: false,
          success (res) {
            if (res.confirm) {
              // value1 = that.data.value1
            }
          }
        })
    }
    var number = this.data.number
    if(number > 100){
      that.setData({
        number: "100"
      })
      }
    number = this.data.number
    
    // console.log(value1)
    // console.log(type2)
    // console.log(type3)
    // console.log(type4)
    // var num = value1*1 + value2*1 + value3*1 + value4*1
    var num = number*1
		if(num){
			this.setData({
	      number: num
	    })
		}
    
  },
  //事件处理函数
  bindViewTap: function() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  // 审核选项卡
  toTables: function (event) {
    console.log(event);
    console.log(event.currentTarget.dataset.typeid);
    // var typeTid = event.currentTarget.dataset.typetid;
    var typeId = event.currentTarget.dataset.typeid;
    // app.globalData.typeId = event.currentTarget.dataset.typeid;
    // var functions = event.currentTarget.dataset.function;
    this.setData({
      currentReviewId:event.currentTarget.dataset.typeid,
    });
  },
  onLoad: function (){
    this.setData({
      height: wx.getSystemInfoSync().windowHeight - 116.2,　　//屏幕高度
      width:wx.getSystemInfoSync().windowWidth　　//屏幕宽度
    })
    // this.submit(params)    
  },
  submit:function(){
    var that = this
    var score = this.data.number
    var params = this.options
    const type1 = 0
    const type2 = 0
    const type3 = 0
    const type4 = 0
    // const type1 = this.data.value1
    // const type2 = this.data.value2
    // const type3 = this.data.value3
    // const type4 = this.data.value4
    wx.request({
      url: host+'api/expertpending/submit',
      data:{expert_id:app.globalData.id,book_id:params.id,article_type:params.article_type,score:score,type1:type1,type2:type2,type3:type3,type4:type4},
      success: function(res){
        // console.log(res)
        if(res.data.sta == 1){
          wx.reLaunch({
            url: `./index`
          })
           wx.showToast({
             title:res.data.msg,
             icon:'success',
             duration:1000
           })
        }else if(res.data.sta == 2){
          wx.showToast({
             title:res.data.msg,
             icon:'none',
             duration:2000
           })
        }
        
      },
      fail: function(data){
        // console.log(data)
      }
    })
  },
  getUserInfo: function(e) {
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  }
})
